package com.ruoyi.chat.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.chat.domain.FriendMessage;
import com.ruoyi.chat.service.IFriendMessageService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 好友消息记录Controller
 * 

 * @date 2023-07-20
 */
@RestController
@RequestMapping("/message")
public class FriendMessageController extends BaseController
{
    @Autowired
    private IFriendMessageService friendMessageService;

    /**
     * 查询好友消息记录列表
     */
    @RequiresPermissions("chat:message:list")
    @GetMapping("/list")
    public TableDataInfo list(FriendMessage friendMessage)
    {
        startPage();
        List<FriendMessage> list = friendMessageService.selectFriendMessageList(friendMessage);
        return getDataTable(list);
    }

    /**
     * 导出好友消息记录列表
     */
    @RequiresPermissions("chat:message:export")
    @Log(title = "好友消息记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FriendMessage friendMessage)
    {
        List<FriendMessage> list = friendMessageService.selectFriendMessageList(friendMessage);
        ExcelUtil<FriendMessage> util = new ExcelUtil<FriendMessage>(FriendMessage.class);
        util.exportExcel(response, list, "好友消息记录数据");
    }

    /**
     * 获取好友消息记录详细信息
     */
    @RequiresPermissions("chat:message:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(friendMessageService.selectFriendMessageById(id));
    }

    /**
     * 新增好友消息记录
     */
    @RequiresPermissions("chat:message:add")
    @Log(title = "好友消息记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FriendMessage friendMessage)
    {
        FriendMessage friendMessage1 = friendMessageService.insertFriendMessage(friendMessage);
        System.out.println("插入成功的id："+friendMessage1.getId());
        return success(friendMessage1);
    }

    /**
     * 修改好友消息记录
     */
    @RequiresPermissions("chat:message:edit")
    @Log(title = "好友消息记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FriendMessage friendMessage)
    {
        return toAjax(friendMessageService.updateFriendMessage(friendMessage));
    }

    /**
     * 删除好友消息记录
     */
    @RequiresPermissions("chat:message:remove")
    @Log(title = "好友消息记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(friendMessageService.deleteFriendMessageByIds(ids));
    }
}
